﻿/********************************************************************++

Copyright (c) Microsoft Corporation. All rights reserved.

************************************************************************/

using System;
using System.Web;
using Microsoft.Health;
using Microsoft.Health.Web;

/// <summary>
/// This page is the Action URL where the app will be redirected with the wcToken
/// </summary>
public partial class TrialRedirect : System.Web.UI.Page
{
    /// <summary>
    /// On page load recieve the token from platform and save the PersonInfo into a cookie
    /// </summary>
    /// <param name="sender">sender argument</param>
    /// <param name="eventArgs">events argument</param>
    protected void Page_Load(object sender, EventArgs eventArgs)
    {
        try
        {
            // Get the authorization token
            string authToken = HttpContext.Current.Request.Params[/*WebApplicationConfiguration.QueryStringToken*/"WCToken"];

            if (!String.IsNullOrEmpty(authToken))
            {
                // Get the person info
                PersonInfo personInfo = WebApplicationUtilities.GetPersonInfo(authToken);
                // Save the person information in Cookie
                WebApplicationUtilities.SavePersonInfoToCookie(HttpContext.Current, personInfo);

                // Redirecting to the default page
                Response.Redirect("./Default.aspx" + "?PersonInfo=" + "Initialized");
            }
            else
            {
                Response.Redirect("./Default.aspx");
            }
        }
        catch (Exception exception)
        {
            //Failed to create the person info.
        }
    }
}
